<template>
  <el-card class="card">
    <div slot="header" class="clearfix">
      <span>{{ popData.title }}</span>
    </div>
    <el-form
      :model="form"
      class="form"
      label-width="70px"
      :disabled="popData.type === 2"
      label-position="right"
    >
      <el-form-item label=" 标签">
        <el-input v-model="form.tags" placeholder="请填写 标签" />
      </el-form-item>
      <el-row>
        <el-col v-if="popData.type !== 2" :span="6" >
          <el-form-item>
            <el-button type="primary" @click="edit">{{ loadingText }}</el-button>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item>
            <router-link :to="`/questionLabel/index`" style="margin-right: 5px">
              <el-button type="primary">取消</el-button>
            </router-link>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </el-card>
</template>
<script>
import sysQuestionLabel from '@/api/questionLabel'
export default {
  props: ['popData'],
  data() {
    return {
      form: {
        id: ''
      },
      loadingText: '保存'
    }
  },
  created() {
    const id = this.popData.id
    if (id) {
      this.form.id = id
      this.loadingText = '编辑'
      this.getDetailById(id)
    } else {
      this.loadingText = '保存'
    }
  },
  methods: {
    getDetailById(id) {
      sysQuestionLabel.getById(id).then(res => {
        this.form = res.data
      })
    },
    edit() {
      sysQuestionLabel.edit(this.form).then(res => {
        this.$message.success(res.message)
        this.$router.push('/questionLabel/index')
      })
    }
  }
}
</script>
<style>
@import "../../styles/dialogForm.scss";
.form{
  width: 80%;
}
</style>
